<template>
	<view class="container">
		<view class="search-view-container">
			<view class="search-view">
				<image class="search-view-icon" src="../../../static/images/search@3x.png"></image>
				<input
					maxlength="10"
					class="search-view-input"
					focus="true"
					placeholder="请输入商品名称"
					placeholder-class="input-placeholder"
					@confirm="clickSearch"
					v-model="keyword"
				/>
			</view>
			<view class="search-view-btn-container"><view class="text" @click="clickSearch">搜索</view></view>
		</view>
		<empty v-if="mallList.length == 0" ></empty>
		<view v-else class="sell-container">
			<mall-product-card class="sell-item" v-for="(item, index) in mallList" :key="index" :itemData="item" @clickProductItem="clickProductItem(item.Id)"></mall-product-card>
		</view>
	</view>
</template>

<script>
import mallProductCard from '@/pages/mall/components/mall-product-card.vue';
import { errorToShow } from '@/config/common.js';
import { listMallProduct } from '@/constant/mall.js';
export default {
	components: {
		mallProductCard
	},
	data() {
		return {
			mallList: [],
			query_filter: {
				CaterotyId: '',
				KeyWords: '',
				pageNum: 1,
				pageSize: 10
			},
			keyword: ''
		};
	},
	onLoad() {},
	onReachBottom() {
		this.query_filter.pageNum++;
		this.searchProductList();
	},
	onPullDownRefresh() {
		this.query_filter.pageNum = 1;
		this.searchProductList();
	},
	methods: {
		clickSearch() {
			this.query_filter.pageNum = 1;
			this.query_filter.KeyWords = this.keyword;
			this.mallList = [];
			this.searchProductList();
		},
		async searchProductList() {
			if (this.query_filter.KeyWords) {
				let res = await listMallProduct(this.query_filter);
				this.mallList =res.data
				uni.stopPullDownRefresh();
				// if (this.query_filter.pageNum > 0) {
				// 	for (let i = 0; i < list.length; i++) {
				// 		let obj = list[i];
				// 		this.mallList.push(obj);
				// 	}
				// } else {
				// 	this.mallList = list;
				// }
				// if (res.Source.length == 0) {
				// 	this.pageIndex--;
				// }
			} else {
				errorToShow('请输入查询内容');
				return;
			}
		},
		clickProductItem(productId) {
			uni.navigateTo({
				url: '../malldetail/index?productId=' + productId
			});
		}
	}
};
</script>

<style scoped lang="scss">
.container {
}

.sell-container {
	display: flex;
	flex-wrap: wrap;
	padding-left: 30rpx;
	padding-right: 30rpx;
	background: transp;
	justify-content: space-between;
	padding-bottom: 30rpx;
	padding-top: 20rpx;
	overflow: hidden;
	.sell-item {
		width: calc(50% - 12rpx);
		margin-bottom: 20rpx;
	}
}

.search-btn {
	margin-left: auto;
	margin-right: 20rpx;
	padding: 0 20rpx;
	height: 60rpx;
	color: #fff;
	font-size: 28rpx;
	line-height: 60rpx;
	border-radius: 8rpx;
	background-color: #bf3261;
}

.search-view-container {
	padding: 10rpx;
	display: flex;
	justify-content: space-between;
	align-items: center;
	padding-left: 30rpx;
	padding-right: 30rpx;
	.search-view-btn-container {
		width: 70rpx;
		margin-left: 20rpx;
		font-size: $main-text-size-30;
		color: $main-text-color-gray-33;
	}
	.search-view {
		display: flex;
		align-items: center;
		background-color: $main-page-color;
		height: 60rpx;
		border-radius: 30rpx;
		width: 100%;
		.input-placeholder {
			font-size: $main-text-size-28;
			color: $main-text-color-grey;
		}

		&-icon {
			width: 30rpx;
			height: 30rpx;
			margin-left: 30rpx;
			margin-right: 20rpx;
		}
		&-input {
			font-size: $main-text-size-28;
			color: $main-text-color-gray-33;
			width: 80%;
		}
	}
}
.empty {
	height: 94vh;
	line-height: 320rpx;
	text-align: center;
	color: #b5b5b7;
}
</style>
